
setwd("c:/users/james/desktop/dropbox/transparency_and_democracy/transparencyindex/PAReplicationMaterials/PostPred Checks/")


library(arm)
library(foreign)
library(rjags)
library(R2jags)

load("c:/users/james/desktop/dropbox/transparency_and_democracy/transparencyindex/PAReplicationMaterials/Index Properties/TransparencyIndex2013.RData")

attach.jags(results)
#TePCP<-cbind(1:500)

for (j in 1:240){
  eval(parse(text=sprintf("p.hat%s <- cbind(1:3875)", j)))
  eval(parse(text=sprintf("xb%s <- cbind(1:3875)",j)))
  eval(parse(text=sprintf("diff%s <- cbind(1:3875)", j)))
}

for (t in 1:500){
  k <- 0
  for (c in 1:125){
    for (y in 1:31){
      k <- k+1
      for (j in 1:240){
        eval(parse(text=sprintf("xb%s[k] <- beta%s[%s,1] + beta%s[%s,2]*transparency[%s,%s,%s]",j, j, t,j, t,t,c,y)))
        eval(parse(text=sprintf("p.hat%s[k] <- 1/(1+exp(-xb%s[k]))", j,j)))
      }
    }
  }
  TePCP[t] <- 0
  for (j in 1:240){
    eval(parse(text=sprintf("diff%s <- 1 - abs(WDIdata$var_%s - p.hat%s)",j,j,j)))
    eval(parse(text=sprintf("TePCP[t] <- TePCP[t] + mean(diff%s)", j)))
  }
}


